﻿
package extremefx.conditions {

	/**
	 * @author Marcelo Volmaro
	 */
	public final class DateValidator extends Validator {

		private var _date:Number;
		
		public function DateValidator(pValue:Date, pArgumentName:String, pAdditionalMessage:String = null) {
			super(pValue, pArgumentName, pAdditionalMessage);
			_date = pValue.getTime();
		}
		
		public function isInRange(pMin:Date, pMax:Date, pDescription:String = null):DateValidator {
			if (pMin.getTime() <= _date && _date <= pMax.getTime()) return this;
			
			throw _buildException(
				_getFormattedConditionMessage(
					Resources.m_betAB, 
					pDescription, 
					_argumentName,
					pMin,
					pMax
				),
				
				RangeError
			);
		}
		
		public function isNotInRange(pMin:Date, pMax:Date, pDescription:String = null):DateValidator {
			if (_date <= pMin.getTime() || pMax.getTime() <= _date) return this;
			
			throw _buildException(
				_getFormattedConditionMessage(
					Resources.m_notBetAB, 
					pDescription, 
					_argumentName,
					pMin,
					pMax
				),
				
				RangeError
			);
		}
		
		public function isGreaterThan(pMin:Date, pDescription:String = null):DateValidator {
			if (pMin.getTime() < _date) return this;
			
			throw _buildException(
				_getFormattedConditionMessage(
					Resources.m_greatA, 
					pDescription, 
					_argumentName,
					pMin
				),
				
				RangeError
			);
		}
		
		public function isGreaterOrEqualThan(pMin:Date, pDescription:String = null):DateValidator {
			if (pMin.getTime() <= _date) return this;
			
			throw _buildException(
				_getFormattedConditionMessage(
					Resources.m_greatEqA, 
					pDescription, 
					_argumentName,
					pMin
				),
				
				RangeError
			);
		}
		
		public function isLessThan(pMax:Date, pDescription:String = null):DateValidator {
			if (_date < pMax.getTime()) return this;
			
			throw _buildException(
				_getFormattedConditionMessage(
					Resources.m_smallA, 
					pDescription, 
					_argumentName,
					pMax
				),
				
				RangeError
			);
		}
		
		public function isLessOrEqualThan(pMax:Date, pDescription:String = null):DateValidator {
			if (_date <= pMax.getTime()) return this;
			
			throw _buildException(
				_getFormattedConditionMessage(
					Resources.m_smallEqA, 
					pDescription, 
					_argumentName,
					pMax
				),
				
				RangeError
			);
		}
		
		public function isEqualTo(pValue:Date, pDescription:String = null):DateValidator {
			if (_date == pValue.getTime()) return this;
			
			throw _buildException(
				_getFormattedConditionMessage(
					Resources.m_eqA, 
					pDescription, 
					_argumentName,
					pValue
				)
			);
		}
		
		public function isNotEqualTo(pValue:Date, pDescription:String = null):DateValidator {
			if (_date != pValue.getTime()) return this;
			
			throw _buildException(
				_getFormattedConditionMessage(
					Resources.m_notEqA, 
					pDescription, 
					_argumentName,
					pValue
				)
			);
		}
	}
}
